package com.example.stock.controller;

import com.example.stock.comm.FreqEnum;
import com.example.stock.comm.StrategyEnum;
import com.example.stock.entity.service.IProBarFundService;
import com.example.stock.entity.service.IStockStatService;
import com.example.stock.service.IServiceStatistics;
import com.example.stock.util.StockStatUtil;
import com.example.stock.vo.DataVo;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.List;

@RestController
@RequestMapping("/api/fund_analysis")
public class FundAnalysisController {
    @Resource
    private IStockStatService stockStatService;
    @Resource
    private IProBarFundService proBarFunService;

    @Resource
    private IServiceStatistics serviceStatistics;
    
    @Resource
    private StockStatUtil stockStatUtil;

    @RequestMapping("statistics_30")
    public Object statistics_30(String tsCode,@RequestParam(required = false) LocalDateTime startTime,String strategy) {
//        stockStatUtil.startStatistics();
        List<DataVo> closeData = proBarFunService.getRowData30(tsCode,startTime);
        serviceStatistics.statistics(closeData, tsCode, FreqEnum.MIN30, StrategyEnum.getByNameExt(strategy));
        return "success!";
    }

    @RequestMapping("analysis_30")
    public Object analysis_30(int m,int n, String tsCode,@RequestParam(required = false) LocalDateTime startTime,String strategy) {
        List<DataVo> closeData = proBarFunService.getRowData30(tsCode, startTime);
        Double finalMoney = stockStatService.analysis(m,n, closeData,true, tsCode, FreqEnum.MIN30, StrategyEnum.getByNameExt(strategy));
        return finalMoney;
    }

    @RequestMapping("statistics_60")
    public Object statistics_60(String tsCode, LocalDateTime startTime,String strategy) {
        stockStatUtil.startStatistics();
        List<DataVo> closeData = proBarFunService.getRowData60(tsCode,startTime);
        serviceStatistics.statistics(closeData, tsCode,FreqEnum.MIN60, StrategyEnum.getByNameExt(strategy));
        return "success!";
    }

    @RequestMapping("analysis_60")
    public Object analysis_60(int m,int n,String tsCode,LocalDateTime startTime,String strategy) {
        List<DataVo> closeData = proBarFunService.getRowData60(tsCode,startTime);
        Double finalMoney = stockStatService.analysis(m,n, closeData,true, tsCode,FreqEnum.MIN60, StrategyEnum.getByNameExt(strategy));
        return finalMoney;
    }
}
